<?php
    require_once './config.php';
    $id = $_GET['id'];//目标id
    $name=$_POST['name'];//目标名字
    $imgname = $_FILES['pic']['name'];//图片名称
    
        //判断 文件名是否存在
    // if($_FILES['pic']['name']){
                //移动文件(图片临时地址,需要存放的地址以及图片名字)
        // move_uploaded_file($tmp,"../".$filepath.$imgname);

        // //sql更新语句

        // $sql="UPDATE `login` SET user = '$name', images = '$file' WHERE id='$id'";
        //     //sql执行语句
        // if (mysqli_query($conn,$sql)>0){
        //     echo "<script>alert('修改成功');location.href = '../index.php'</script>";
        // }

    // }else{
    //     echo "<script>alert('文件不存在');location.href = '../edit.php?id=$id'</script>";
    // }

    if($imgname) {  //判断是否有修改图片
        $tmp = $_FILES['pic']['tmp_name'];//存放图片的临时地址
        $filepath = 'img/';//路径
        $file = $filepath.$imgname;//存放图片的完整路径
        move_uploaded_file($tmp,"../".$filepath.$imgname);

        //sql更新语句
        $sql="UPDATE `login` SET user = '$name', images = '$file' WHERE id='$id'";
        //sql执行语句
        if (mysqli_query($conn,$sql)>0){
            echo "<script>alert('修改成功');location.href = '../index.php'</script>";
        }
    } else {
        $sql="UPDATE `login` SET user = '$name' WHERE id='$id'";
            //sql执行语句
        if (mysqli_query($conn,$sql)>0){
            echo "<script>alert('修改成功');location.href = '../index.php'</script>";
        }
    }
    
?>